using System;

namespace OracleInternal.Secure.Network
{
	internal class DiffieHellman
	{
		private static readonly int m_a = 257;

		private byte[] m_b;

		private int c;

		private byte[] d;

		private int e;

		private byte[] f;

		private byte[] g;

		private ushort h;

		private ushort i;

		private ushort[] j = new ushort[DiffieHellman.m_a];

		private ushort[] k = new ushort[DiffieHellman.m_a];

		private byte[] l;

		private int m;

		private int n;

		private int o;

		private byte[] p;

		private static readonly ushort[] q = new ushort[5]
		{
			40,
			41,
			56,
			128,
			256
		};

		private static readonly ushort[] r = new ushort[5]
		{
			40,
			64,
			56,
			128,
			256
		};

		private static readonly ushort[] s = new ushort[5]
		{
			80,
			112,
			112,
			512,
			512
		};

		private static readonly ushort[] t = new ushort[5]
		{
			300,
			512,
			512,
			512,
			512
		};

		private static readonly byte[] u = new byte[38]
		{
			2,
			83,
			179,
			242,
			166,
			141,
			61,
			187,
			106,
			195,
			153,
			9,
			192,
			215,
			4,
			5,
			242,
			91,
			130,
			97,
			107,
			122,
			232,
			220,
			29,
			123,
			3,
			150,
			53,
			226,
			219,
			239,
			67,
			102,
			250,
			208,
			76,
			193
		};

		private static readonly byte[] v = new byte[38]
		{
			12,
			54,
			129,
			183,
			4,
			71,
			3,
			160,
			120,
			96,
			81,
			38,
			140,
			234,
			155,
			188,
			163,
			62,
			124,
			1,
			171,
			54,
			139,
			34,
			117,
			152,
			119,
			102,
			53,
			197,
			128,
			213,
			36,
			210,
			80,
			99,
			184,
			243
		};

		private static readonly byte[] w = new byte[64]
		{
			130,
			152,
			222,
			73,
			222,
			247,
			9,
			229,
			224,
			13,
			176,
			160,
			165,
			156,
			169,
			242,
			61,
			246,
			198,
			167,
			233,
			74,
			68,
			163,
			225,
			135,
			46,
			245,
			76,
			31,
			161,
			122,
			223,
			92,
			242,
			117,
			129,
			237,
			81,
			195,
			38,
			238,
			139,
			225,
			4,
			3,
			30,
			103,
			80,
			83,
			181,
			124,
			75,
			69,
			111,
			21,
			74,
			23,
			86,
			11,
			90,
			21,
			149,
			165
		};

		private static readonly byte[] x = new byte[64]
		{
			220,
			142,
			163,
			27,
			8,
			96,
			105,
			138,
			204,
			246,
			209,
			158,
			135,
			14,
			52,
			252,
			103,
			197,
			89,
			11,
			78,
			166,
			177,
			60,
			213,
			253,
			239,
			21,
			172,
			157,
			95,
			63,
			33,
			76,
			220,
			7,
			204,
			135,
			74,
			179,
			1,
			215,
			127,
			44,
			67,
			51,
			81,
			60,
			222,
			11,
			30,
			206,
			100,
			71,
			118,
			87,
			92,
			81,
			204,
			152,
			179,
			254,
			231,
			239
		};

		private static readonly byte[][] y = new byte[5][]
		{
			u,
			w,
			w,
			w,
			w
		};

		private static readonly byte[][] z = new byte[5][]
		{
			v,
			x,
			x,
			x,
			x
		};

		private DiffieHellman(int A_0)
		{
			a(null, null, A_0);
		}

		public DiffieHellman(byte[] A_0, byte[] A_1, int A_2)
		{
			a(A_0, A_1, A_2);
		}

		public DiffieHellman(byte[] A_0, byte[] A_1, ushort A_2, ushort A_3)
		{
			if (A_0 != null && A_1 != null)
			{
				f = A_0;
				g = A_1;
				i = A_3;
				h = A_2;
			}
			else
			{
				a(A_0, A_1, 40);
			}
		}

		private void a(byte[] A_0, byte[] A_1, int A_2)
		{
			this.m_b = A_0;
			if (A_0 != null)
			{
				c = A_0.Length;
			}
			else
			{
				c = 0;
			}
			d = A_1;
			if (A_1 != null)
			{
				e = A_1.Length;
			}
			else
			{
				e = 0;
			}
			a(A_2);
		}

		public byte[] getPublicKey()
		{
			a();
			return l;
		}

		public byte[] getSessionKey(byte[] pkey_data, int pkey_size)
		{
			a(pkey_data, pkey_size);
			return p;
		}

		private void b(byte[] A_0, int A_1)
		{
			new Class_b().a(A_0, A_1);
		}

		private void a(int A_0)
		{
			for (int i = 0; i < q.Length; i++)
			{
				if (A_0 >= q[i] && A_0 <= r[i])
				{
					h = s[i];
					this.i = t[i];
					f = new byte[(this.i + 7) / 8];
					g = new byte[(this.i + 7) / 8];
					if (c * 8 >= this.i && e * 8 >= this.i)
					{
						Array.Copy(this.m_b, 0, f, 0, f.Length);
						Array.Copy(d, 0, g, 0, g.Length);
					}
					else
					{
						Array.Copy(y[i], 0, f, 0, f.Length);
						Array.Copy(z[i], 0, g, 0, g.Length);
					}
					break;
				}
			}
			if (f != null)
			{
				_ = g;
			}
		}

		private void a()
		{
			ushort[] array = new ushort[257];
			ushort[] array2 = new ushort[257];
			byte[] array3 = new byte[512];
			int num = (ushort)(h + 7) >> 3;
			int num2 = (ushort)(i + 7) >> 3;
			m = (ushort)num2;
			n = (int)i / 16 + 1;
			l = new byte[m];
			b(array3, num);
			array3[0] &= (byte)(255 >> num - 8 * h);
			global::Class_a.a(array, n, f, num2);
			global::Class_a.a(k, n, array3, num);
			global::Class_a.a(j, n, g, num2);
			global::Class_a.c(array2, array, k, j, n);
			global::Class_a.a(l, m, array2, n);
		}

		private void a(byte[] A_0, int A_1)
		{
			ushort[] array = new ushort[DiffieHellman.m_a];
			ushort[] array2 = new ushort[DiffieHellman.m_a];
			o = m;
			p = new byte[o];
			global::Class_a.a(array, n, A_0, A_1);
			global::Class_a.c(array2, array, k, j, n);
			global::Class_a.a(p, o, array2, n);
		}
	}
}
